package outputstream_;

import java.io.*;

/**
 * @author DCSGO
 * @version 1.0
 * BufferedInputStream BufferedOutputStream
 * 模拟拷贝文件
 * 字节流既可以操作二进制文件也可以操作文本文件
 */
public class BufferedCopy {
    public static void main(String[] args) {
        String srcFilePath = "D:\\src\\01. Lost Game.flac";
        String destFilePath = "E:\\dest\\Lost Game.copy.flac";
        BufferedInputStream bi = null;
        BufferedOutputStream bo = null;
        try {
            bi = new BufferedInputStream(new FileInputStream(srcFilePath));
            bo = new BufferedOutputStream(new FileOutputStream(destFilePath));
            int readLen;
            byte[] buf = new byte[1024];
            while ((readLen = bi.read(buf)) != -1) {
                bo.write(buf, 0, readLen);
            }
            System.out.println("拷贝完成...");

        } catch (IOException e) {
            e.getStackTrace();
        } finally {
            try {
                if (bi != null) {
                    bi.close();
                }
                if (bo != null) {
                    bo.close();
                }
            } catch (IOException e) {
                e.getStackTrace();
            }
        }
    }
}
